<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2019/3/22 0022
 * Time: 19:10
 */

namespace app\admin\model;

use think\Model;
class AuthRule extends Model
{
    public function sort($pid=0,$level=0,$class=0){
        $data=$this->select();
        static $arr=array();
        foreach ($data as $k=>$v){
            if($v['pid']==$pid){
                if($v['level']==0){
                    $v['class']="id-".$v['id'];
                }
                else{
                    $v['class']=$class ."-" . $v['id'];
                }
                $v['level']=$level;
                $arr[]=$v;
                $this->sort($v['id'],$level+1,$v['class']);
            }
        }

        return $arr;

    }
    public function getChild($id){
        static $arr=array();
        $data=$this->select();
        foreach ($data as $k=>$v){
            if($v['pid']==$id){
                $arr[]=$v['id'];
                $this->getChild($v['id']);
            }
        }
        return $arr;
    }
}